package com.nycreativity.elecreativity.entity.vo.shoppingcart

import com.nycreativity.elecreativity.entity.vo.PageDataVO
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty
import java.util.stream.Collectors

/**
 * @description 购物车查询VO
 * @author sxt
 * @date 2021/4/19 11:50 上午
 * @version 1.0
 */
@ApiModel("购物车查询VO")
class ShoppingCartVO(
    /**
     * 购物车具体商品信息
     */
    @ApiModelProperty("购物车具体商品信息")
    val shoppingCartItemVOs: PageDataVO<ShoppingCartItemVO>
) {

    /**
     * 购物车中商品的总金额
     */
    @get:ApiModelProperty("购物车中商品的总金额")
    val totalAmount: Double by lazy {
        shoppingCartItemVOs.records?.stream()?.collect(
            Collectors.summingDouble { it.allAmount.toDouble() }) ?: 0.0
    }

}